package cn.fl.fgi.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.commons.result.ResponseData;
import cn.fl.fgi.api.condition.FgiBusInfoQueryCondition;
import cn.fl.fgi.service.IFgiBusInfoservice;
import cn.fl.fgi.vo.FgiBusInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @description 业务信息 控制层
 * @author: fengzuoxiang
 * @date: 19:56 2020/4/10
 * @version V1.0
 */
@Controller
@RequestMapping("/fgi/fgibusinfo")
public class FgiBusInfoController extends BaseController {

    @Autowired
    private IFgiBusInfoservice fgiBusInfoservice;

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {

        String busSourceType = request.getParameter("busSourceType");
        ModelAndView view = new ModelAndView("fgi/fgibusinfo/fgiBusInfoSubmitDetailList");
        if(StringUtils.isNotEmpty(busSourceType)){
            view = new ModelAndView("fgi/fgibusinfo/fgiBusInfoSubmitDetailList1");
            view.addObject("busSourceType", busSourceType);
        }
        // 项目类型
        List<KeyValueVO> projectTypeList = this.fgiBusInfoservice.getKvPrjTypeList();
        // 事业部
        List<KeyValueVO> orgList = this.fgiBusInfoservice.getKvOrgList();
        view.addObject("orgListList", orgList);
        view.addObject("projectTypeList", projectTypeList);
        BaseLogUtils.newWebLogger("加载每日上报数据详情页面").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();
        return view;
    }

    /**
     * 到上报页面
     */
    @RequestMapping(value = "/toSubmitPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("fgi/fgibusinfo/fgiBusInfoSubmitList");
        // 项目类型
        List<KeyValueVO> projectTypeList = this.fgiBusInfoservice.getKvPrjTypeList();

        // 事业部
        List<KeyValueVO> orgList = this.fgiBusInfoservice.getKvOrgList();
        view.addObject("orgListList", orgList);
        view.addObject("projectTypeList", projectTypeList);
        BaseLogUtils.newWebLogger("加载金融数据上报管理页面").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();
        return view;
    }

    /**
     * 到上报页面
     */
    @RequestMapping(value = "/toMakeSureSubmitPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toMakeSureSubmitPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("fgi/fgibusinfo/fgiBusInfoMakeSureSubmitList");
        // 项目类型
        List<KeyValueVO> projectTypeList = this.fgiBusInfoservice.getKvPrjTypeList();

        // 事业部
        List<KeyValueVO> orgList = this.fgiBusInfoservice.getKvOrgList();
        view.addObject("orgListList", orgList);
        view.addObject("projectTypeList", projectTypeList);
        BaseLogUtils.newWebLogger("加载金融数据确认上报管理页面").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();
        return view;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object initList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newWebLogger("初始化列表").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String isSub = request.getParameter("isSub");
        String guaranteeRateMin = request.getParameter("guaranteeRateMin");
        String guaranteeRateMax = request.getParameter("guaranteeRateMax");
        String startTime = request.getParameter("startTm");
        String endTime = request.getParameter("endTm");
        String busSourceType = request.getParameter("busSourceType");
        String busSource = request.getParameter("busSource");
        String busSourceId = request.getParameter("busSourceId");
        String cstNm = request.getParameter("cstNm");
        String prjOrg = request.getParameter("prjOrg");
        String prjType = request.getParameter("prjType");
        String fundNm = request.getParameter("fundNm");
        String isRisk = request.getParameter("isRisk");
        String overdueDayMin = request.getParameter("overdueDayMin");
        String overdueDayMax = request.getParameter("overdueDayMax");
        if(StringUtils.isEmpty(isSub)){
            BaseLogUtils.newWebLogger("是否已上报参数为空!").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return null;
        }

        Pager page = new Pager();

        FgiBusInfoQueryCondition fgiBusInfoQueryCondition = new FgiBusInfoQueryCondition();
        fgiBusInfoQueryCondition.setIsSub(Integer.valueOf(isSub));
        if(StringUtils.isNotEmpty(currentPage) && StringUtils.isNotEmpty(pageSize)){
            fgiBusInfoQueryCondition.setCurrent(Long.valueOf(currentPage));
            fgiBusInfoQueryCondition.setSize(Long.valueOf(pageSize));
        }
        if(StringUtils.isNotEmpty(guaranteeRateMin)){
            fgiBusInfoQueryCondition.setGuaranteeRateMin(guaranteeRateMin);
        }
        if(StringUtils.isNotEmpty(guaranteeRateMax)){
            fgiBusInfoQueryCondition.setGuaranteeRateMax(guaranteeRateMax);
        }
        if(StringUtils.isNotEmpty(startTime)){
            fgiBusInfoQueryCondition.setStartTime(DateUtils.formatStringToDate(startTime,DateUtils.YYYY_MM_DD));
        }
        if(StringUtils.isNotEmpty(endTime)){
            fgiBusInfoQueryCondition.setEndTime(DateUtils.formatStringToDate(endTime,DateUtils.YYYY_MM_DD));
        }
        if(StringUtils.isNotEmpty(busSourceType)){
            fgiBusInfoQueryCondition.setBusSourceType(busSourceType);
        }
        if(StringUtils.isNotEmpty(busSource)){
            fgiBusInfoQueryCondition.setBusSource(busSource);
        }
        if(StringUtils.isNotEmpty(busSourceId)){
            fgiBusInfoQueryCondition.setBusSourceId(busSourceId);
        }
        if(StringUtils.isNotEmpty(cstNm)){
            fgiBusInfoQueryCondition.setCstNm(cstNm);
        }
        if(StringUtils.isNotEmpty(prjOrg)){
            fgiBusInfoQueryCondition.setPrjOrg(prjOrg);
        }
        if(StringUtils.isNotEmpty(prjType)){
            fgiBusInfoQueryCondition.setPrjType(prjType);
        }
        if(StringUtils.isNotEmpty(fundNm)){
            fgiBusInfoQueryCondition.setFundNm(fundNm);
        }
        if(StringUtils.isNotEmpty(isRisk)){
            fgiBusInfoQueryCondition.setIsRisk(Integer.valueOf(isRisk));
        }
        if(StringUtils.isNotEmpty(overdueDayMin)){
            fgiBusInfoQueryCondition.setOverdueDayMin(Integer.valueOf(overdueDayMin));
        }
        if(StringUtils.isNotEmpty(overdueDayMax)){
            fgiBusInfoQueryCondition.setOverdueDayMax(Integer.valueOf(overdueDayMax));
        }
        page.setCondition(fgiBusInfoQueryCondition);
        BaseLogUtils.newWebLogger("初始化列表").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .setKeys("page", JSON.toJSONString(page))
                .info();
        try {
            ListPageVO<FgiBusInfoVO> listPage = null;
            Pager pager = this.fgiBusInfoservice.searchListPage(page);
            if(null != pager){
                List<FgiBusInfoVO> list = (List<FgiBusInfoVO>) pager.getResultList();
                if(CollectionUtils.isNotEmpty(list)){
                    // 项目类型
                    List<KeyValueVO> projectTypeList = this.fgiBusInfoservice.getKvPrjTypeList();
                    // 事业部
                    List<KeyValueVO> orgList = this.fgiBusInfoservice.getKvOrgList();
                    for (FgiBusInfoVO fgiBusInfoVO : list) {
                        if(StringUtils.isNotEmpty(fgiBusInfoVO.getPrjType())){
                            for (KeyValueVO keyValueVO : projectTypeList) {
                                if(fgiBusInfoVO.getPrjType().equals(keyValueVO.getKey())){
                                    fgiBusInfoVO.setPrjTypeNm(keyValueVO.getValue());
                                }
                            }
                        }
                        if(StringUtils.isNotEmpty(fgiBusInfoVO.getPrjOrg())){
                            for (KeyValueVO keyValueVO : orgList) {
                                if(fgiBusInfoVO.getPrjOrg().equals(keyValueVO.getKey())){
                                    fgiBusInfoVO.setPrjOrgNm(keyValueVO.getValue());
                                }
                            }
                        }
                        if(StringUtils.isNotEmpty(fgiBusInfoVO.getGuaranteeType()) && "1".equals(fgiBusInfoVO.getGuaranteeType())){
                            fgiBusInfoVO.setGuaranteeType("借款担保");
                        }
                    }
                }

                listPage = new ListPageVO<>(list, page.getTotalCount());
            }else{
                listPage = new ListPageVO<>(new ArrayList<>(), 0);
            }
            BaseLogUtils.newWebLogger("加载列表页面").setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setKeys("listPage", JSON.toJSONString(listPage))
                    .info();
            return listPage;
        } catch (BaseException ex) {
            BaseLogUtils.newWebLogger("加载列表页面失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            BaseLogUtils.newWebLogger("加载列表页面失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return null;
    }

    /**
     * 上报
     */
    @RequestMapping(value = "/submit.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object submit(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "上报操作成功!");
        String guaranteeRateMin = request.getParameter("guaranteeRateMin");
        String guaranteeRateMax = request.getParameter("guaranteeRateMax");
        String startTime = request.getParameter("startTm");
        String endTime = request.getParameter("endTm");
        String busSourceType = request.getParameter("busSourceType");
        String busSource = request.getParameter("busSource");
        String busSourceId = request.getParameter("busSourceId");
        String cstNm = request.getParameter("cstNm");
        String prjOrg = request.getParameter("prjOrg");
        String prjType = request.getParameter("prjType");
        String fundNm = request.getParameter("fundNm");
        String isRisk = request.getParameter("isRisk");
        String overdueDayMin = request.getParameter("overdueDayMin");
        String overdueDayMax = request.getParameter("overdueDayMax");
        String isSub = request.getParameter("isSub");
        if(StringUtils.isEmpty(isSub)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_PARAM_IS_BAD);
            BaseLogUtils.newWebLogger("是否已上报参数为空!").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }
        if(StringUtils.isEmpty(isRisk)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_PARAM_IS_BAD);
            BaseLogUtils.newWebLogger("是否风险上报参数为空!").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }
        Long subUsrId = CurrentThreadContext.getCurrentUserId();
        if(StringUtils.isEmpty(subUsrId)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_PARAM_IS_BAD);
            BaseLogUtils.newWebLogger("获取当前操作人ID失败!").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }

        FgiBusInfoQueryCondition fgiBusInfoQueryCondition = new FgiBusInfoQueryCondition();
        fgiBusInfoQueryCondition.setIsRisk(Integer.valueOf(isRisk));
        fgiBusInfoQueryCondition.setIsSub(Integer.valueOf(isSub));
        fgiBusInfoQueryCondition.setSubUsrId(subUsrId);
        if(StringUtils.isNotEmpty(guaranteeRateMin)){
            fgiBusInfoQueryCondition.setGuaranteeRateMin(guaranteeRateMin);
        }
        if(StringUtils.isNotEmpty(guaranteeRateMax)){
            fgiBusInfoQueryCondition.setGuaranteeRateMax(guaranteeRateMax);
        }
        if(StringUtils.isNotEmpty(startTime)){
            fgiBusInfoQueryCondition.setStartTime(DateUtils.formatStringToDate(startTime,DateUtils.YYYY_MM_DD));
        }
        if(StringUtils.isNotEmpty(endTime)){
            fgiBusInfoQueryCondition.setEndTime(DateUtils.formatStringToDate(endTime,DateUtils.YYYY_MM_DD));
        }
        if(StringUtils.isNotEmpty(busSourceType)){
            fgiBusInfoQueryCondition.setBusSourceType(busSourceType);
        }
        if(StringUtils.isNotEmpty(busSource)){
            fgiBusInfoQueryCondition.setBusSource(busSource);
        }
        if(StringUtils.isNotEmpty(busSourceId)){
            fgiBusInfoQueryCondition.setBusSourceId(busSourceId);
        }
        if(StringUtils.isNotEmpty(cstNm)){
            fgiBusInfoQueryCondition.setCstNm(cstNm);
        }
        if(StringUtils.isNotEmpty(prjOrg)){
            fgiBusInfoQueryCondition.setPrjOrg(prjOrg);
        }
        if(StringUtils.isNotEmpty(prjType)){
            fgiBusInfoQueryCondition.setPrjType(prjType);
        }
        if(StringUtils.isNotEmpty(fundNm)){
            fgiBusInfoQueryCondition.setFundNm(fundNm);
        }
        if(StringUtils.isNotEmpty(overdueDayMin)){
            fgiBusInfoQueryCondition.setOverdueDayMin(Integer.valueOf(overdueDayMin));
        }
        if(StringUtils.isNotEmpty(overdueDayMax)){
            fgiBusInfoQueryCondition.setOverdueDayMax(Integer.valueOf(overdueDayMax));
        }
        BaseLogUtils.newWebLogger("上报数据参数").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .setKeys("fgiBusInfoQueryCondition", JSON.toJSONString(fgiBusInfoQueryCondition))
                .info();
        try {
            ResponseData responseData = this.fgiBusInfoservice.submitFgiBusInfo(fgiBusInfoQueryCondition);
            if(responseData.isSuccess()){
                BaseLogUtils.newWebLogger("上报数据成功").setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .setKeys("responseData", JSON.toJSONString(responseData))
                        .info();
            }else{
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(responseData.getMessage());
                BaseLogUtils.newWebLogger("上报数据失败").setLogOperType(LogOperEnum.REQ)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("上报数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("上报数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;

    }

    /**
     * 确认上报
     */
    @RequestMapping(value = "/makeSureSubmit.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object makeSureSubmit(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "确认上报操作成功!");
        String guaranteeRateMin = request.getParameter("guaranteeRateMin");
        String guaranteeRateMax = request.getParameter("guaranteeRateMax");
        String startTime = request.getParameter("startTm");
        String endTime = request.getParameter("endTm");
        String busSourceType = request.getParameter("busSourceType");
        String busSource = request.getParameter("busSource");
        String busSourceId = request.getParameter("busSourceId");
        String cstNm = request.getParameter("cstNm");
        String prjOrg = request.getParameter("prjOrg");
        String prjType = request.getParameter("prjType");
        String fundNm = request.getParameter("fundNm");
        String isRisk = request.getParameter("isRisk");
        String overdueDayMin = request.getParameter("overdueDayMin");
        String overdueDayMax = request.getParameter("overdueDayMax");
        String isSub = request.getParameter("isSub");
        if(StringUtils.isEmpty(isSub)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_PARAM_IS_BAD);
            BaseLogUtils.newWebLogger("是否已上报参数为空!").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }
        FgiBusInfoQueryCondition fgiBusInfoQueryCondition = new FgiBusInfoQueryCondition();
        fgiBusInfoQueryCondition.setIsSub(Integer.valueOf(isSub));
        if(StringUtils.isNotEmpty(isRisk)){
            fgiBusInfoQueryCondition.setIsRisk(Integer.valueOf(isRisk));
        }
        if(StringUtils.isNotEmpty(guaranteeRateMin)){
            fgiBusInfoQueryCondition.setGuaranteeRateMin(guaranteeRateMin);
        }
        if(StringUtils.isNotEmpty(guaranteeRateMax)){
            fgiBusInfoQueryCondition.setGuaranteeRateMax(guaranteeRateMax);
        }
        if(StringUtils.isNotEmpty(startTime)){
            fgiBusInfoQueryCondition.setStartTime(DateUtils.formatStringToDate(startTime,DateUtils.YYYY_MM_DD));
        }
        if(StringUtils.isNotEmpty(endTime)){
            fgiBusInfoQueryCondition.setEndTime(DateUtils.formatStringToDate(endTime,DateUtils.YYYY_MM_DD));
        }
        if(StringUtils.isNotEmpty(busSourceType)){
            fgiBusInfoQueryCondition.setBusSourceType(busSourceType);
        }
        if(StringUtils.isNotEmpty(busSource)){
            fgiBusInfoQueryCondition.setBusSource(busSource);
        }
        if(StringUtils.isNotEmpty(busSourceId)){
            fgiBusInfoQueryCondition.setBusSourceId(busSourceId);
        }
        if(StringUtils.isNotEmpty(cstNm)){
            fgiBusInfoQueryCondition.setCstNm(cstNm);
        }
        if(StringUtils.isNotEmpty(prjOrg)){
            fgiBusInfoQueryCondition.setPrjOrg(prjOrg);
        }
        if(StringUtils.isNotEmpty(prjType)){
            fgiBusInfoQueryCondition.setPrjType(prjType);
        }
        if(StringUtils.isNotEmpty(fundNm)){
            fgiBusInfoQueryCondition.setFundNm(fundNm);
        }
        if(StringUtils.isNotEmpty(overdueDayMin)){
            fgiBusInfoQueryCondition.setOverdueDayMin(Integer.valueOf(overdueDayMin));
        }
        if(StringUtils.isNotEmpty(overdueDayMax)){
            fgiBusInfoQueryCondition.setOverdueDayMax(Integer.valueOf(overdueDayMax));
        }
        BaseLogUtils.newWebLogger("确认上报数据参数").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .setKeys("fgiBusInfoQueryCondition", JSON.toJSONString(fgiBusInfoQueryCondition))
                .info();
        try {
            ResponseData responseData = this.fgiBusInfoservice.makeSureSubmitFgiBusInfo(fgiBusInfoQueryCondition);
            if(responseData.isSuccess()){
                BaseLogUtils.newWebLogger("确认上报数据成功").setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .setKeys("responseData", JSON.toJSONString(responseData))
                        .info();
            }else{
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(responseData.getMessage());
                BaseLogUtils.newWebLogger("确认上报数据失败").setLogOperType(LogOperEnum.REQ)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("确认上报数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("确认上报数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;

    }

    /**
     * 刷新数据
     */
    @RequestMapping(value = "/submitData.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object submitData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
        try {
            ResponseData responseData = this.fgiBusInfoservice.submitData();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("操作失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("操作失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;

    }

    /**
     * 刷新数据
     */
    @RequestMapping(value = "/checkData.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object checkData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
        try {
            ResponseData responseData = this.fgiBusInfoservice.checkData();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("操作失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("操作失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;

    }

    /**
     * 刷新数据
     */
    @RequestMapping(value = "/getData.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object getData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
        String startTime = request.getParameter("startTm");
        String endTime = request.getParameter("endTm");
        if(StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请填写开始时间,结束时间");
            BaseLogUtils.newWebLogger("开始时间,结束时间为空!").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }

        try {
            ResponseData responseData = this.fgiBusInfoservice.getData(DateUtils.formatStringToDate(startTime, DateUtils.YYYY_MM_DD), DateUtils.formatStringToDate(endTime, DateUtils.YYYY_MM_DD));
            if(responseData.isSuccess()){
                BaseLogUtils.newWebLogger("操作成功").setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .setKeys("responseData", JSON.toJSONString(responseData))
                        .info();
            }else{
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(responseData.getMessage());
                BaseLogUtils.newWebLogger("操作失败").setLogOperType(LogOperEnum.REQ)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("操作失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("操作失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;

    }

    /**
     * 到根据支付表查看上报数据详情页面
     */
    @RequestMapping(value = "/toSubmitDetailPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toSubmitDetailPage(HttpServletRequest request, HttpServletResponse response) {

        String busSourceId = request.getParameter("busSourceId");
        String busSource = request.getParameter("busSource");
        String busSourceType = request.getParameter("busSourceType");
        ModelAndView view = new ModelAndView("fgi/fgibusinfo/fgiBusInfoSubmitDetailPage");
        view.addObject("busSourceId", busSourceId);
        view.addObject("busSource", busSource);
        view.addObject("busSourceType", busSourceType);

        BaseLogUtils.newWebLogger("加载根据支付表查看上报数据详情页面").setLogOperType(LogOperEnum.REQ)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();
        return view;
    }

    /**
     * 根据支付表号获取提交数据
     */
    @RequestMapping(value = "/getSubmitDetailByBusSourceId.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object getSubmitDetailByBusSourceId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
        String busSourceId = request.getParameter("busSourceId");
        String busSource = request.getParameter("busSource");
        String busSourceType = request.getParameter("busSourceType");
        if(StringUtils.isEmpty(busSourceId)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("查询异常");
            BaseLogUtils.newWebLogger("业务唯一编号(支付报表)为空").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0001);
            return result;
        }

        try {
            JSONObject data = this.fgiBusInfoservice.getSubmitDetailByPayNo(busSourceId, busSource, busSourceType);
            if(null != data){
                result.setData(data);
                BaseLogUtils.newWebLogger("操作成功").setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .setKeys("responseData", JSON.toJSONString(data))
                        .info();
            }else{
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("查询失败");
                BaseLogUtils.newWebLogger("查询失败").setLogOperType(LogOperEnum.REQ)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("操作失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.newWebLogger("操作失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return result;

    }

}

